package mainControlsTest;

import junit.framework.TestCase;
import mainControls.RoomChecker;
import smallTools.SimpleTime;
import entities.Room;
import entities.Section;
import entities.Staff;

public class RoomCheckerTest extends TestCase {

	private RoomChecker rmChecker;

	public void setUp() {
		rmChecker = new RoomChecker();
	}

	public void tearDown() {
		Room.clear();
		Staff.clear();
		Section.clear();
	}

	public void test_roomTooLarge() {
		new Room("rm1", 200);
		Section section = new Section("sectionId1", 30, 2, "staffId1");
		SimpleTime startTime = new SimpleTime("Mon", 12, 30);

		Boolean isSuccess = rmChecker.check(section, startTime);
		assertFalse(isSuccess);
		assertNull(rmChecker.getAllocatedRoomId());
	}

	public void test_findImmediately() {
		new Room("rm1", 30);
		Section section = new Section("sectionId1", 30, 2, "staffId1");
		SimpleTime startTime = new SimpleTime("Mon", 12, 30);

		Boolean isSuccess = rmChecker.check(section, startTime);
		assertTrue(isSuccess);
		assertEquals("rm1", rmChecker.getAllocatedRoomId());
	}

	public void test_roomInUse() {
		Room rm1 = new Room("rm1", 30);
		Section sectionInRoom1 = new Section("sectionInRoom1", 30, 2,
				"staffInRoom1");
		SimpleTime startTimeInRoom1 = new SimpleTime("Mon", 12, 30);
		sectionInRoom1.setSectionStartTime(startTimeInRoom1);
		sectionInRoom1.setSectionRoom("rm1");
		rm1.addSection("sectionInRoom1");

		new Room("rm2", 30);
		Section sectionTest = new Section("sectionTest", 30, 2, "staffTest");
		SimpleTime startTimeTest = new SimpleTime("Mon", 12, 30);

		Boolean isSuccess = rmChecker.check(sectionTest, startTimeTest);
		assertTrue(isSuccess);
		assertEquals("rm2", rmChecker.getAllocatedRoomId());
	}
}
